package in.smartride.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.datepicker.client.DateBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CopyOfSmartRide implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	int height = Window.getClientHeight();
	int width = Window.getClientWidth();

	public void onModuleLoad() {

		DecoratorPanel findRide = createPanel("Find");
		DecoratorPanel offerRide = createPanel("Offer");
		DockPanel dock = new DockPanel();
		dock.add(findRide, DockPanel.EAST);
		dock.add(offerRide, DockPanel.WEST);
		dock.setSpacing(10);

		RootPanel.get().add(dock, width / 2 - width / 5,
				height / 2 - height / 5);

	}

	private DecoratorPanel createPanel(String str) {
		DecoratorPanel panel = new DecoratorPanel();
		panel.setPixelSize(width / 5, height / 5);
		// Create a table to layout the form options
		FlexTable layout = new FlexTable();
		layout.setCellSpacing(6);
		FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();

		// Add a title to the form
		layout.setTitle(str + " Ride");
		layout.setHTML(0, 0, str + " Ride");
		cellFormatter.setColSpan(0, 0, 2);
		cellFormatter.setHorizontalAlignment(0, 0,
				HasHorizontalAlignment.ALIGN_CENTER);

		MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
		// get from list
		String[] words = { "abhimanyu", "hitesh", "vishnu", "abhishek" };
		for (int i = 0; i < words.length; ++i) {
			oracle.add(words[i]);
		}

		// Create the from suggest box
		SuggestBox fromSuggestBox = new SuggestBox(oracle);
		fromSuggestBox.ensureDebugId("cwSuggestBox");

		// Create the to suggest box
		SuggestBox toSuggestBox = new SuggestBox(oracle);
		fromSuggestBox.ensureDebugId("cwSuggestBox");

		// Add some standard form options
		layout.setHTML(1, 0, "from");
		layout.setWidget(1, 1, fromSuggestBox);
		layout.setHTML(2, 0, "to");
		layout.setWidget(2, 1, toSuggestBox);
		layout.setHTML(3, 0, "date");
		layout.setWidget(3, 1, new DateBox());

		// add button
		Button button = new Button(str, new ClickHandler() {
			public void onClick(ClickEvent event) {
				Window.alert("to be implemented");
			}
		});
		button.ensureDebugId("cwBasicButton-normal");
		layout.setWidget(4, 1, button);

		panel.setWidget(layout);
		return panel;
	}
}
